package com.gitee.flyzing.jxt.component;

import org.apache.poi.ss.usermodel.Row;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JXTEachRow extends JXTRow {
    public JXTEachCell jxtEachCell;

    public static JXTRow createJXTEachRow(JXTEachCell jxtEachCell) {
        JXTEachRow jxtEachRow = new JXTEachRow();
        jxtEachRow.setJxtEachCell(jxtEachCell);
        return jxtEachRow;
    }

    public void setJxtEachCell(JXTEachCell jxtEachCell) {
        this.jxtEachCell = jxtEachCell;
    }

    public List<JXTRow> getJXTRows(Row row) {
        List<JXTRow> jxtRows = new ArrayList<>();
        if (jxtEachCell != null) {
            String itemName = jxtEachCell.getItemName();
            Map params = new HashMap<>();
            params.put("itemName", itemName);

            List items = jxtEachCell.getItems();
            for (int i = 0; i < items.size(); i++) {
                Object item = items.get(i);
                JXTRow jxtRow = JXTRow.createJXTRow(row, item, params);
                jxtRows.add(jxtRow);
            }
        }
        return jxtRows;
    }
}
